﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mamnontuoitho7.AppCode;
using System.Data;

namespace mamnontuoitho7.backend
{
    public partial class ClassList : System.Web.UI.Page
    {
        public Class _class = new Class();
        private ClassCategory _classCategory = new ClassCategory();
        protected DataTable _dtClass;

        protected void Page_Load(object sender, EventArgs e)
        {

            //Check Role Admin
            if (Session["memberID"].ToString() != "" && (ConstantClass.permissionInfo).IndexOf(Session["role"].ToString() + ",") != -1)
            {
                try
                {
                    //Put Class Category into Drop down list
                    if (!IsPostBack)
                    {
                        DataTable dttClassCategory = _classCategory.GetAllClassCategory();

                        ddlClassCategory.DataSource = dttClassCategory;
                        ddlClassCategory.DataTextField = "ClassCategoryName";
                        ddlClassCategory.DataValueField = "ClassCategoryID";
                        ddlClassCategory.DataBind();

                        //add select dropdownlist
                        ddlClassCategory.Items.Insert(0, new ListItem("Xem Tất Cả", "0"));

                        //Get Class List
                        _dtClass = _class.GetClassList("0");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Response.Redirect(ConstantClass._errorAdminPage);
                }
            }
            else
            {
                Response.Redirect(ConstantClass._errorLoginPage);
            }
        }


        /// <summary>
        /// Event of Class Category Dropdownlist
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlClassCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                _dtClass = _class.GetClassList(ddlClassCategory.SelectedValue);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Response.Redirect(ConstantClass._errorAdminPage);
            }
        }

    }
}